﻿using System;
using System.Data;
using System.Data.SqlClient;
using Repository.DatabaseType;
using Model.Domain_Model;

namespace Repository
{
    public class RoadTable
    {
        private SqlConnection connection = null;
        private SqlServer2008 database = null;

        public RoadTable()
        {
        }

        public RoadTable(SqlConnection connection, SqlServer2008 database)
        {
            this.connection = connection;
            this.database = database;
        }

        public void NewRoad(Road road, Valuation valuation)
        {
            SqlCommand cmd = new SqlCommand(SqlDefinitions.Road.newRoad, connection);
            database.OpenConnection();
            cmd.Parameters.AddWithValue("@fromCountry", road.fromCountry);
            cmd.Parameters.AddWithValue("@fromCity", road.fromCity);
            cmd.Parameters.AddWithValue("@toCountry", road.toCountry);
            cmd.Parameters.AddWithValue("@toCity", road.toCity);
            cmd.Parameters.AddWithValue("@idClient", road.idClient);
            cmd.Parameters.AddWithValue("@idType", road.idType);
            cmd.Parameters.AddWithValue("@value", valuation.value);
            cmd.Parameters.AddWithValue("@idCurrency", valuation.idCurrency);
            cmd.ExecuteNonQuery();
            database.CloseConnection();
        }
    }
}
